﻿var main = window.main = {
    init: function () {
        var ts = this;
        ts.bookMark();
        ts.setHome();
        jQuery(".index-big-banner").slide({ mainCell: ".bd", autoPlay: true });
    },
    setHome: function () {

        $(document).on('click', '.setHome', function (e) {
            try {
                obj.style.behavior = 'url(#default#homepage)';
                obj.setHomePage(window.location.href);
            } catch (e) {
                if (window.netscape) {
                    try {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                    } catch (e) {
                        alert("抱歉，您所使用的浏览器无法完成此操作！\n\n您需要手动设置为首页");
                    }
                } else {
                    alert("抱歉，您所使用的浏览器无法完成此操作！\n\n您需要手动设置为首页");
                }
            }
        });
    },
    bookMark: function (url, title) {
        $(document).on("click", ".addfav", function (e) {
            e.preventDefault();
            var u = url || window.location.href,
                t = title || document.title;
            try {
                window.external.AddFavorite(u, t);
            } catch (e) {
                try {
                    window.sidebar.addPanel(t, u, "");
                } catch (e) {
                    return alert("请您尝试同时按下Ctrl和D键收藏本页");
                }
            }
        });
    },
    tabs: function (ele, cla, con, evt) {
        var evt = evt ? evt : "mouseenter";
        $(ele).bind(evt, function () {
            var index = $(this).index();
            $(this).addClass(cla).siblings().removeClass(cla);
            $(con).eq(index).show().siblings().hide();
        }).eq(0).trigger(evt)
    },
    hoverSwitch: function (way, hoverThis, hoverClass, switchObject, n, speed, interval) {
        var canSwitch = true;
        function switchNow($this, canSwitch) {
            var switchObjectLen = switchObject.length, NowIndex = $this.index(), css_z = "z-index";
            $this.addClass(hoverClass).siblings().removeClass(hoverClass);
            for (var i = 0; i < switchObjectLen; i++) {
                var $nowLi = $(switchObject[i] + ":eq(" + NowIndex + ")"),
						$nowLi_s = $nowLi.siblings(),
						$visible = $(switchObject[i] + ":visible"),
						visible_z = parseInt($visible.css(css_z));
                visible_z = visible_z ? visible_z : 1;
                if (speed) {
                    if (interval) { canSwitch = false };
                    $nowLi_s.css(css_z, visible_z - 1).stop();
                    $nowLi.css(css_z, visible_z).fadeTo(speed, 1, function () {
                        $nowLi_s.hide();
                        if (interval) { canSwitch = true };
                    });
                } else {
                    $nowLi.show();
                    $nowLi_s.hide();
                };
            };
        };
        function autoSwitch() {
            var autoLen = $(hoverThis).length;
            if (canSwitch) {
                var i = $(hoverThis).filter(function (index) {
                    if ($(this).hasClass(hoverClass)) {
                        return $(this);
                    };
                }).index();
                i++;
                if (i >= autoLen) { i = 0 };
                switchNow($(hoverThis).eq(i), canSwitch);
            };
        };
        if (way == "click") {
            $(hoverThis).click(function () {
                switchNow($(this));
            });
            $(hoverThis).eq(n).click();
        } else {
            $(hoverThis).mouseenter(function () {
                switchNow($(this));
            });
            $(hoverThis).eq(n).mouseenter();
        };
        if (interval) {
            setInterval(autoSwitch, interval);
            $(hoverThis + "," + switchObject[0]).hover(function () {
                canSwitch = false;
            }, function () {
                canSwitch = true;
            });
        };
    }

};

$(function () {

    main.init();
});